#include "mainwindowimpl.h"
#include "net.h"
#include "imagemodel.h"
#include <QBitArray>
#include <QTableView>
#include <QDebug>
#include "setoptionsdlg.h"
//
const int h =5;
const int w =5;
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f){
	setupUi(this);
	crActn->trigger();

	connect(ImgTblVw, SIGNAL(clicked( const QModelIndex &)), lnEdt, SLOT(setFocus()));
}
//

void MainWindowImpl::on_Btn_clicked(){
	if(net->isInit())
		inquireImgActn->trigger();
	else{
		addImgActn->trigger();
		if(net->isInit()) lbl->setText(trUtf8("Ищите"));
	}
}

void MainWindowImpl::on_addImgActn_triggered(){
	net->addImage(*b, lnEdt->text().at(0));
	charsList->addItem(lnEdt->text().at(0));
	lnEdt->setText("");
	qDebug()<<"on_addImgActn_triggered";
}

void MainWindowImpl::on_inquireImgActn_triggered(){
	lnEdt->setText(net->inquire(*b));
}

void MainWindowImpl::on_crActn_triggered(){
	SetOptionsDlg dlg(this);
	dlg.exec();
	qDebug()<<dlg.nChars();
	qDebug()<<dlg.w();
	qDebug()<<dlg.h();

	net = new Net(dlg.h(), dlg.w(), dlg.nChars(), this);
	b = new QBitArray(dlg.h() * dlg.w(), false);

	ImageModel * m = new ImageModel(b, dlg.h(), dlg.w(), this);
	ImgTblVw->setModel(m);
	ImgTblVw->resizeColumnsToContents();
	ImgTblVw->resizeRowsToContents();
}
